package com.gcb.controller.order;

import com.gcb.common.annotation.Log;
import com.gcb.controller.BaseController;
import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.core.page.TableDataInfo;
import com.gcb.common.enums.BusinessType;
import com.gcb.common.utils.poi.ExcelUtil;
import com.gcb.domain.dto.OrderShipQueryDTO;
import com.gcb.domain.dto.OrderShipSaveDTO;
import com.gcb.domain.vo.OrderShipVO;
import com.gcb.service.IOrderShipService;
import com.gcb.framework.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/orderShip")
@Tag(name = "后台船源订单管理", description = "后台船源订单管理")
public class OrderShipController extends BaseController {

    @Resource
    private IOrderShipService OrderShipService;

    /**
     * 发布船源订单
     *
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:add')")
    @PostMapping("/add")
    @Operation(summary = "702.发布船源订单")
    public AjaxResult add(@RequestBody OrderShipSaveDTO dto) {
        OrderShipService.add(dto, SecurityUtils.getUserId());
        return success();
    }

    /**
     * 编辑船源订单
     *
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:update')")
    @PostMapping("/update")
    @Operation(summary = "703.编辑船源订单")
    public AjaxResult update(@RequestBody OrderShipSaveDTO dto) {
        OrderShipService.update(dto, SecurityUtils.getUserId());
        return success();
    }

    /**
     * 船员订单列表
     *
     * @param queryDTO
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:list')")
    @PostMapping("/list")
    @Operation(summary = "701.船员订单列表")
    public TableDataInfo list(@RequestBody OrderShipQueryDTO queryDTO) {
        startPage();
        List<OrderShipVO> list = OrderShipService.list(queryDTO);
        return getDataTable(list);
    }

    /**
     * 船源详情接口
     *
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:getDetail')")
    @GetMapping("/getDetail")
    @Operation(summary = "705.船源详情接口")
    public AjaxResult detail(Long id) {
        OrderShipVO vo = OrderShipService.getDetail(id);
        return success(vo);
    }

    /**
     * 批量更新订单状态
     *
     * @param ids
     * @param state
     * @return
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:batchUpdateState')")
    @PostMapping("/batchUpdateState")
    @Operation(summary = "706.批量更新订单状态")
    public AjaxResult batchUpdateState(Long[] ids, Integer state) {
        OrderShipService.batchUpdateState(ids, state);
        return success();
    }

    /**
     * 导出船源订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderShip:export')")
    @Log(title = "船源订单管理导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "704.导出船源订单")
    public void export(HttpServletResponse response, OrderShipQueryDTO queryDTO) {
        List<OrderShipVO> list = OrderShipService.list(queryDTO);
        ExcelUtil<OrderShipVO> util = new ExcelUtil<>(OrderShipVO.class);
        util.exportExcel(response, list, "船源订单管理导出");
    }
}
